"use strict";
var vm;
$(function () {
    var params = getParamsFromUrl();
  var lessonID=params[0].split('=')[1];
   var phase=params[1].split('=')[1];
   setUpVue(lessonID,phase);
});
function getParamsFromUrl() {
    var url = decodeURI(location.href);
    var urlParmListStr = url.substr(url.indexOf('?') + 1, url.length);
    var param1 = urlParmListStr.split("&");
    return param1;
}

function setUpVue(lessonID,phase){
vm= new Vue({
    el:'#container',
    data:{
        readyhwk:[],
        unreadyhwk:[],
        lesson:{}
    },
    methods: {
        getReadyHWK:function(){
                    var url='homework/'+UserID+'/'+lessonID+'/'+phase+'/labdone';
                    $.get(url,function(data){
                            if(data){
                              vm.readyhwk=data
                            }
                        
                    })
        },
        getUnReadyHWK:function(){
    var url='homework/'+UserID+'/'+lessonID+'/'+phase+'/labdoing';
                    $.get(url,function(data){
                            if(data){
                              vm.unreadyhwk=data
                            }
                        
                    })
        },
        getLessonInfo:function(){
          var url='publishlessons/'+lessonID+'/'+phase+'/lessoninfo';
             $.get(url,function(data){
                            if(data){
                              vm.lesson=data
                            }
                        
                    })
        },
        submitWebAns:function(index){
            var url='homework/'+UserID+'/'+lessonID+'/'+phase+'/'+this.unreadyhwk[index].id;
            var param={url:this.unreadyhwk[index].url};
               $.ajax({
                    url:url,
                    type:"POST",
                    data:JSON.stringify(param),
                    contentType:"application/json",
                    dataType:"json",
                    success:function(data){
                        if(data) {
                            //success

                            layer.msg(langThis("hwk_success"));
                      
                        
                        }
                        else {
                            layer.msg(langThis("hwk_fail"));
                        }
                    },
                    error:function(event){
                        layer.msg(langThis("hwk_fail"));
                    }
                });
        },
        modifyWebAns:function (index){
              var url='homework/'+UserID+'/'+lessonID+'/'+phase+'/'+this.readyhwk[index].id;
            var param={url:this.readyhwk[index].url};
               $.ajax({
                    url:url,
                    type:"PUT",
                    data:JSON.stringify(param),
                    contentType:"application/json",
                    dataType:"json",
                    success:function(data){
                        if(data) {
                            //success

                            layer.msg(langThis("hwk_success"));
                      
                        
                        }
                        else {
                            layer.msg(langThis("hwk_fail"));
                        }
                    },
                    error:function(event){
                        layer.msg(langThis("hwk_fail"));
                    }
                });
        }
    },
    mounted :function(){
      this.getLessonInfo(),
         this.getReadyHWK(),
       this.getUnReadyHWK()
    }
})
}